layui.use(['form', 'admin', 'ax', 'laydate', 'upload', 'formSelects', 'layer'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var layer = layui.layer;


    //获取详情信息，填充表单
    var ajax = new $ax(Feng.ctxPath + "/databaseListKh/list?id=" + Feng.getUrlParam("id"));
    var result = ajax.start();
    // console.log(result.data[0].password)

    $("#id").val(Feng.getUrlParam("id"))


    /**
     * 判断原密码是否正确
     */
    $("#beforePassword").blur(function () {
        if ($("#beforePassword").val() != result.data[0].password) {
            layer.open({
                type: 0,
                title: '信息',
                content: '<span style="color: red">输入密码与原密码不一致</span>',
                yes: function () {
                    $("#beforePassword").val("")
                    layer.closeAll()
                }
            })
        }
    })


    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        /**
         * 判断两次新密码输入是否一致
         */
            console.log(data.field)
        var yes = 1;
        if (data.field.password != data.field.newPassword) {
            layer.open({
                type: 0,
                title: '信息',
                content: '<span style="color: red">两次新密码输入不一致</span>',
                yes: function () {
                    $("#password").val("")
                    $("#newPassword").val("")
                    layer.closeAll()
                    return yes
                }
            })
            if (yes == 1) {
                return
            }
        }
        var ajax = new $ax(Feng.ctxPath + "/databaseListKh/editItem", function (data) {
            Feng.success("修改密码成功！");
            //传给上个页面，刷新table用
            admin.putTempData('formOk', true);
            //关掉对话框
            admin.closeThisDialog();
        }, function (data) {
            Feng.error("修改密码失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();

        return false;
    });

});